#include "processdocumentautocomplete.h"

using namespace core;
using namespace swp;

ProcessDocumentAutocomplete* processDocumentAutocomplete = 0;

ProcessDocumentAutocomplete* ProcessDocumentAutocomplete::getInstance()
{
    if (processDocumentAutocomplete == 0)
    {
        processDocumentAutocomplete = new ProcessDocumentAutocomplete();
    }

    return processDocumentAutocomplete;
}

void ProcessDocumentAutocomplete::destroy()
{
    delete processDocumentAutocomplete;
    processDocumentAutocomplete = 0;
}

void ProcessDocumentAutocomplete::refreshSwimlanes(IDocumentData* data,
    const QList<QString>& workers)
{
    if (workers.size() == 0 && m_swimlanes.contains(data))
    {
        m_swimlanes.remove(data);
    }
    else
    {
        m_swimlanes[data] = workers;
    }
}

QList<QString> ProcessDocumentAutocomplete::getSwimlanes(
    IDocumentData* data) const
{
    QList<QString> ret;

    if (m_swimlanes.contains(data))
    {
        ret = m_swimlanes[data];
    }

    return ret;
}

void ProcessDocumentAutocomplete::refreshInputs(IDocumentData* data,
    const QList<QString>& resourcesArtifacts)
{
    if (resourcesArtifacts.size() == 0 && m_inputs.contains(data))
    {
        m_inputs.remove(data);
    }
    else
    {
        m_inputs[data] = resourcesArtifacts;
    }
}

QList<QString> ProcessDocumentAutocomplete::getInputs(
    IDocumentData* data) const
{
    QList<QString> ret;

    if (m_inputs.contains(data))
    {
        ret = m_inputs[data];
    }

    return ret;
}

void ProcessDocumentAutocomplete::refreshOutputs(IDocumentData* data,
    const QList<QString>& artifacts)
{
    if (artifacts.size() == 0 && m_outputs.contains(data))
    {
        m_outputs.remove(data);
    }
    else
    {
        m_outputs[data] = artifacts;
    }
}

QList<QString> ProcessDocumentAutocomplete::getOutputs(
    IDocumentData* data) const
{
    QList<QString> ret;

    if (m_outputs.contains(data))
    {
        ret = m_outputs[data];
    }

    return ret;
}

ProcessDocumentAutocomplete::ProcessDocumentAutocomplete() :
    m_swimlanes(),
    m_inputs(),
    m_outputs()
{

}

ProcessDocumentAutocomplete::~ProcessDocumentAutocomplete()
{

}
